// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sysin

import (
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// AuctionLogUpdateFields 修改竞拍记录字段过滤
type AuctionLogUpdateFields struct {
	AuctionId            int64       `json:"auctionId"            dc:"竞拍活动"`
	ProductId            int64       `json:"productId"            dc:"产品"`
	FinalPrice           float64     `json:"finalPrice"           dc:"最终成交价格"`
	NumberOfParticipants int         `json:"numberOfParticipants" dc:"参与人数"`
	BidLog               *gjson.Json `json:"bidLog"               dc:"出价日志"`
	Date                 *gtime.Time `json:"date"                 dc:"日期"`
	StartTime            *gtime.Time `json:"startTime"            dc:"开始时间"`
	EndTime              *gtime.Time `json:"endTime"              dc:"结束时间"`
}

// AuctionLogInsertFields 新增竞拍记录字段过滤
type AuctionLogInsertFields struct {
	AuctionId            int64       `json:"auctionId"            dc:"竞拍活动"`
	MapperId             int64       `json:"mapperId"             dc:"对应关系id"`
	ProductId            int64       `json:"productId"            dc:"产品"`
	FinalPrice           float64     `json:"finalPrice"           dc:"最终成交价格"`
	NumberOfParticipants int         `json:"numberOfParticipants" dc:"参与人数"`
	BidLog               *gjson.Json `json:"bidLog"               dc:"出价日志"`
	Date                 *gtime.Time `json:"date"                 dc:"日期"`
	StartTime            *gtime.Time `json:"startTime"            dc:"开始时间"`
	EndTime              *gtime.Time `json:"endTime"              dc:"结束时间"`
}

// AuctionLogEditInp 修改/新增竞拍记录
type AuctionLogEditInp struct {
	entity.AuctionLog
}

func (in *AuctionLogEditInp) Filter(ctx context.Context) (err error) {
	// 验证竞拍活动
	if err := g.Validator().Rules("required").Data(in.AuctionId).Messages("竞拍活动不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证产品
	if err := g.Validator().Rules("required").Data(in.ProductId).Messages("产品不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证日期
	if err := g.Validator().Rules("required").Data(in.Date).Messages("日期不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证开始时间
	if err := g.Validator().Rules("required").Data(in.StartTime).Messages("开始时间不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type AuctionLogEditModel struct{}

// AuctionLogDeleteInp 删除竞拍记录
type AuctionLogDeleteInp struct {
	Id interface{} `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *AuctionLogDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type AuctionLogDeleteModel struct{}

// AuctionLogViewInp 获取指定竞拍记录信息
type AuctionLogViewInp struct {
	Id int64 `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *AuctionLogViewInp) Filter(ctx context.Context) (err error) {
	return
}

type AuctionLogViewModel struct {
	Id                   int64       `json:"id"                   dc:"id"`
	AuctionId            int64       `json:"auctionId"            dc:"竞拍活动"`
	MapperId             int64       `json:"mapperId"             dc:"对应关系id"`
	ProductId            int64       `json:"productId"            dc:"产品"`
	FinalPrice           float64     `json:"finalPrice"           dc:"最终成交价格"`
	FinalUserID          int64       `json:"finalUserID"          dc:"最终成交用户id"`
	FinalUserName        string      `json:"finalUserName"        dc:"最终成交用户"`
	BidLog               *gjson.Json `json:"bidLog"               dc:"出价日志"`
	NumberOfParticipants int         `json:"numberOfParticipants" dc:"参与人数"`
	Date                 *gtime.Time `json:"date"                 dc:"日期"`
	StartTime            *gtime.Time `json:"startTime"            dc:"开始时间"`
	EndTime              *gtime.Time `json:"endTime"              dc:"结束时间"`
	ProductName          string      `json:"productName"          dc:"商品名称"`
	ProductMainImage     *gjson.Json `json:"productMainImage"     dc:"商品主图"`
	ProductMarketPrice   float64     `json:"productMarketPrice"         dc:"商品市面价格"`
	Status               int         `json:"status"               dc:"状态(auctionLogStatus)"`
	IsAppointment        bool        `json:"isAppointment"        dc:"是否预约"`
	MBasePrice           float64     `json:"mBasePrice"   dc:"起拍价格"`
	MMinBidPrice         float64     `json:"mMinBidPrice" dc:"最低出价"`
	MStartTime           *gtime.Time `json:"mStartTime"   dc:"当天开始时间"`
	MEndTime             *gtime.Time `json:"mEndTime"     dc:"当天结束时间"`
	ServerTime           *gtime.Time `json:"serverTime"   dc:"服务器当前时间"`
	Rank                 int         `json:"rank"         dc:"排名"` // 0是未参加
	IsSuccess            bool        `json:"isSuccess"     dc:"是否竞拍成功"`
	IsJoin               bool        `json:"isJoin"        dc:"是否参与"`
}

// AuctionLogListInp 获取竞拍记录列表
type AuctionLogListInp struct {
	form.PageReq
	AuctionId int64       `json:"auctionId" dc:"竞拍活动"`
	ProductId int64       `json:"productId" dc:"产品"`
	Date      *gtime.Time `json:"date" dc:"日期"`
	Status    int         `json:"status" dc:"状态"`
}

func (in *AuctionLogListInp) Filter(ctx context.Context) (err error) {
	return
}

type AuctionLogListModel struct {
	Id                   int64       `json:"id"                   dc:"id"`
	AuctionId            int64       `json:"auctionId"            dc:"竞拍活动"`
	MapperId             int64       `json:"mapperId"             dc:"对应关系id"`
	ProductId            int64       `json:"productId"            dc:"产品"`
	FinalPrice           float64     `json:"finalPrice"           dc:"最终成交价格"`
	FinalUserID          int64       `json:"finalUserID"          dc:"最终成交用户id"`
	FinalUserName        string      `json:"finalUserName"        dc:"最终成交用户"`
	BidLog               *gjson.Json `json:"bidLog"               dc:"出价日志"`
	NumberOfParticipants int         `json:"numberOfParticipants" dc:"参与人数"`
	Date                 *gtime.Time `json:"date"                 dc:"日期"`
	StartTime            string      `json:"startTime"            dc:"开始时间"`
	EndTime              string      `json:"endTime"              dc:"结束时间"`
	ProductName          string      `json:"productName"          dc:"商品名称"`
	ProductMainImage     *gjson.Json `json:"productMainImage"     dc:"商品主图"`
	ProductMarketPrice   float64     `json:"productMarketPrice"         dc:"商品市面价格"`
	Status               int         `json:"status"               dc:"状态"`
	IsAppointment        bool        `json:"isAppointment"        dc:"是否预约"`
	MBasePrice           float64     `json:"mBasePrice"   dc:"起拍价格"`
	MMinBidPrice         float64     `json:"mMinBidPrice" dc:"最低出价"`
	MStartTime           *gtime.Time `json:"mStartTime"   dc:"当天开始时间"`
	MEndTime             *gtime.Time `json:"mEndTime"     dc:"当天结束时间"`
	ServerTime           *gtime.Time `json:"serverTime"   dc:"服务器当前时间"`
	IsSuccess            bool        `json:"isSuccess"     dc:"是否竞拍成功"`
}

// AuctionLogExportModel 导出竞拍记录
type AuctionLogExportModel struct {
	Id                   int64       `json:"id"                   dc:"id"`
	AuctionId            int64       `json:"auctionId"            dc:"竞拍活动"`
	MapperId             int64       `json:"mapperId"             dc:"对应关系id"`
	ProductId            int64       `json:"productId"            dc:"产品"`
	FinalPrice           float64     `json:"finalPrice"           dc:"最终成交价格"`
	NumberOfParticipants int         `json:"numberOfParticipants" dc:"参与人数"`
	Date                 *gtime.Time `json:"date"                 dc:"日期"`
	StartTime            *gtime.Time `json:"startTime"            dc:"开始时间"`
	EndTime              *gtime.Time `json:"endTime"              dc:"结束时间"`
	ProductName          string      `json:"productName"          dc:"商品名称"`
	ProductMainImage     *gjson.Json `json:"productMainImage"     dc:"商品主图"`
}

type BidInp struct {
	Id        int64   `json:"id" v:"required#id不能为空" dc:"id"`
	BidAmount float64 `json:"bidAmount" v:"required#出价不能为空" dc:"出价"`
}

func (in *BidInp) Filter(ctx context.Context) (err error) {
	return
}

type BidModel struct {
	UserID              int64       `json:"userId" dc:"用户id"`
	AdminMemberRealName string      `json:"adminMemberRealName" dc:"姓名"`
	AdminMemberUsername string      `json:"adminMemberUsername" dc:"用户名"`
	AdminMemberAvatar   string      `json:"adminMemberAvatar" dc:"头像"`
	BidAmount           float64     `json:"bidAmount" dc:"出价"`
	BidTime             *gtime.Time `json:"bidTime" dc:"出价时间"`
}

type AppointmentInp struct {
	LogID uint64 `json:"logId" v:"required#logId不能为空" dc:"logId"`
}

type AppointmentModel struct {
}

type AuctionMapperApiLogListInp struct {
	form.PageReq
	Status int `json:"status" dc:"状态"`
}

func (in *AuctionMapperApiLogListInp) Filter(ctx context.Context) (err error) {
	return
}

type AuctionMapperApiLogListModel struct {
	Id                      int64       `json:"id"                   dc:"id"`
	LogID                   int64       `json:"logId"                dc:"竞拍记录id"`
	UserID                  int64       `json:"userId"               dc:"用户id"`
	MapperID                int64       `json:"mapperId"             dc:"对应关系id"`
	ProductID               int64       `json:"productId"            dc:"产品id"`
	LogAuctionId            int64       `json:"logAuctionId"            dc:"竞拍活动"`
	LogMapperId             int64       `json:"logMapperId"             dc:"对应关系id"`
	LogProductId            int64       `json:"logProductId"            dc:"产品"`
	LogFinalPrice           float64     `json:"logFinalPrice"           dc:"最终成交价格"`
	LogNumberOfParticipants int         `json:"logNumberOfParticipants" dc:"参与人数"`
	LogDate                 *gtime.Time `json:"logDate"                 dc:"日期"`
	LogStartTime            *gtime.Time `json:"logStartTime"            dc:"开始时间"`
	LogEndTime              *gtime.Time `json:"logEndTime"              dc:"结束时间"`
	LogStatus               int         `json:"logStatus"               dc:"状态(auctionLogStatus)"`
	WasAppointment          bool        `json:"wasAppointment"          dc:"是否已预约"`
	ProductName             string      `json:"productName"          dc:"商品名称"`
	ProductMainImage        *gjson.Json `json:"productMainImage"     dc:"商品主图"`
	MBasePrice              float64     `json:"mBasePrice"   dc:"起拍价格"`
	MMinBidPrice            float64     `json:"mMinBidPrice" dc:"最低出价"`
	MStartTime              *gtime.Time `json:"mStartTime"   dc:"当天开始时间"`
	MEndTime                *gtime.Time `json:"mEndTime"     dc:"当天结束时间"`
}

type AuctionApiLogListInp struct {
	form.PageReq
	Status        []int `json:"status" dc:"状态 1-待开始 2-进行中 3-已结束"`
	IsAppointment bool  `json:"isAppointment" dc:"是否筛选已预约"`
	IsJoin        bool  `json:"isJoin" dc:"是否筛选已参与"`
}

func (in *AuctionApiLogListInp) Filter(ctx context.Context) (err error) {
	if len(in.Status) > 0 {
		for _, status := range in.Status {
			if !validate.InSlice(consts.AuctionLogStatusList, status) {
				return gerror.Newf("状态参数错误, %d不是有效的状态", status)
			}
		}
	}
	return
}
